<template>
  <div class="content">
    <div class="block">
      <el-date-picker
          v-model="dateTimeValue"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
      </el-date-picker>
      <el-button type="primary" style="margin-left: 10px" @click="getLoggerOnline">搜索</el-button>
    </div>
    <div style="display: flex;flex-direction: column;align-items: flex-end;">

      <el-table
          :data="onlineList"
          row-key="id"
          stripe
          :row-style="{height:'40px'}"
          :cell-style="{padding:'0px'}"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
        <el-table-column
            prop="username"
            label="用户名">
        </el-table-column>
        <el-table-column
            prop="type"
            label="类型">
        </el-table-column>
        <el-table-column
            prop="device"
            label="设备">
        </el-table-column>
        <el-table-column
            prop="ip"
            label="IP地址">
        </el-table-column>
        <el-table-column
            prop="logTime"
            label="时间">
        </el-table-column>
        <el-table-column
            label="操作"
            width="200">
          <template slot-scope="scope">
            <el-button @click="deleteById(scope.row)" type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination style="margin-top: 5px"
                     @size-change="currentSizeChange"
                     @current-change="currentChange"
                     :current-page="currentPage"
                     :page-sizes="[10, 20, 30, 40]"
                     :page-size="limit"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination>

    </div>

  </div>
</template>

<script>
export default {
  name: "OnlineList",
  components: {

  },
  data(){
    return{
      page: 1,
      limit: 10,
      total: 0,
      currentPage:1,
      ofType:'',
      onlineList: [],
      form:{
        id:'',
        name:'',
        code:'',
        introduce:'',
      },
      dialogFormVisible:false,
      formLabelWidth:'120px',
      dateTimeValue: ''
    }
  },
  created(){
    this.getLoggerOnline()
  },
  methods:{
    //获取权限列表
    getLoggerOnline(){
      let url = ''
      if(this.dateTimeValue){
        url = 'logger/online/'+this.page+"/"+this.limit+'/'+this.dateTimeValue[0]+'/'+this.dateTimeValue[1];
      }else{
        url = 'logger/online/'+this.page+"/"+this.limit;
      }
      this.$http.get(url).then(res => {
        this.total = res.data.data.data.total
        this.onlineList = res.data.data.data.records
      })
    },
    //页面发生改变
    currentChange(value){
      this.page = value
      this.getLoggerOnline()
    },
    currentSizeChange(value){
      this.limit = value
      this.getLoggerOnline()
    },
    //根据ID删除
    deleteById(row) {
      this.$confirm('确定要删除这条数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let url = 'logger/online/'+row.id
        this.$http.delete(url).then(res=>{
          if(res.data.code===0){
            this.getLoggerOnline()
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //清空表单
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style scoped>

</style>
